<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace app\accessrules;

/*use yii\base\Component;
use yii\base\Action;
use yii\web\User;
use yii\web\Request;*/
use yii\filters\AccessRule;

/**
 * This class represents an access rule defined by the [[AccessControl]] action filter
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class NeaAccessRule extends AccessRule
{
    /**
     * @param User $user the user object
     * @return bool whether the rule applies to the role
     */
    protected function matchRole($user)
    {

        if (empty($this->roles)) {
            return true;
        }
        foreach ($this->roles as $role) {
            if ($role === '?') {
                if ($user->getIsGuest()) {
                    return true;
                }
            } elseif ($role === '@') {
                if (!$user->getIsGuest()) {
                    return true;
                }
            } else if($role === '#'){

              $member = $user->getIdentity();

              if($member){
                if(!$member->can_login){
                  //是#角色（不许登录的角色）
                  return true;
                }
              }
            }
            elseif ($user->can($role)) {
                return true;
            }
        }

        return false;
    }
}
